const {addrFormatError} =require('../constant/err.type')
const validator = (rules) => {
    return async (ctx, next) => {
      try {
         ctx.verifyParams(rules)
      } catch (err) {
        console.error(err);
        addrFormatError.result = err;//将错误信息传递给全局错误处理中间件
        ctx.app.emit("error", addrFormatError, ctx);
        return;
      }

      await next();
    }

  }
  

module.exports = {
  validator, 
}